<template>
	<view class="">
		<view v-if="loading">
			<loading></loading>
		</view>
		<view class="container" v-else>
			<!-- <button class="addBtn" @click="addBtn" size="mini">添加</button> -->
			<view class="topTitle">
				<view class="left">
					<text>题目列表</text>
				</view>
				<view class="right">
					<text  @click="addBtn">新增</text> 
					<text  @click="importBtn">导入</text>
				</view>
			</view>
			<view class="reportView"  @click="open(i)" v-for="(i, index) in list">
				<view class="titleView">
					<text class="blue">{{i.choicesType == 3?'多选':i.choicesType == 0?'单选':'判断'}}</text>
					<text >{{i.subjectName}}</text>
				</view>
				
				<view class="descView">
					<text>{{parseTime(i.createTime,'{y}-{m}-{d}')}}</text>
					<text class="blue">分值:{{i.score}}分</text>
					<text class="blue">正确答案：{{i.answer}}</text>
					<text>难易等级：<uni-rate class="rate" :disabled="true" :size="8" disabledColor="#FFD950" :value="i.level" /></text>
				</view>
			</view>
			<view class="load-more">
				<uni-icons v-if="loadShow" type="spinner-cycle" size="30"></uni-icons>
				<text  v-if="botShow">已经到底了</text>
			</view>
			<uni-popup ref="popup" type="bottom">
				<view class="popup">
					<text @click="update">修改</text>
					<text  class="del">删除</text>
					<text class="cancel" @click="close">取消</text>
				</view>
			</uni-popup>
			<uni-popup ref="popup2"  background-color="#fff" type="bottom">
				<view class="addView">
					<text class="topTitle">题目类型</text>
					<button size="mini" class="publicBtn" @click="choseQues(0)">单选</button>
					<button size="mini" class="publicBtn" @click="choseQues(3)">多选</button>
					<button size="mini" class="publicBtn" @click="choseQues(2)">判断</button>
					<button size="mini" class="publicBtn" >简答</button>
				</view>
			</uni-popup>
			
			
		</view>
			
	</view>
	
</template>
<script>
	import { getQuestionList } from '@/api/exam/exam.js'
	import {parseTime } from '@/utils/ruoyi'
	import loading from '@/components/loading/loading'
	export default{
		data(){
			return{
				cateId:null,
				list:[],
				pageForm:{
					pageNo:1,
					pageSize:10,
				},
				parseTime,
				loadShow:false,
				botShow:false,
				loading:true,
			}
		},
		onLoad(e) {
			this.cateId=e.id
		},
		created() {
			this.getList();
		},
		onReachBottom(){
			if(!this.botShow){
				this.loadShow = true
				this.pageForm.pageNo ++ ;
				this.getList()
			}
			
		},
		methods:{
			open(e){
				this.active=e
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open('bottom')
			},
			close() {
				this.$refs.popup.close()
			},
			addBtn(e) {
				this.$refs.popup2.open('center')
			},
			choseQues(e){
				this.$refs.popup2.close()
				if(e ==0){
					this.$tab.navigateTo(`/pages/work/question/choices?categoryId=`+ this.cateId)
				}else if(e==2){
					this.$tab.navigateTo(`/pages/work/question/judgeMent?categoryId=`+ this.cateId)
				}else if(e==3){
					this.$tab.navigateTo(`/pages/work/question/multipleChoices?categoryId=`+ this.cateId)
				}
				
			},
			importBtn(){
				this.$tab.navigateTo(`/pages/work/question/import`)
			},
			getList(){
				this.pageForm.categoryId=this.cateId 
				getQuestionList(this.pageForm).then(res=>{
					if(res.data.list.length > 0){
						this.list.push(...res.data.list)
						this.loadShow = false
					}else{
						this.loadShow = false
						this.botShow = true
					}
					this.loading = false
				})
			},
			update(){
				this.$refs.popup.close()
				if(this.active.choicesType === 0){
					this.$tab.navigateTo(`/pages/work/question/choices?id=`+ this.active.id)
				}else if(this.active.choicesType === 2){
					this.$tab.navigateTo(`/pages/work/question/judgeMent?id=`+ this.active.id)
				}else if(this.active.choicesType === 3){
					this.$tab.navigateTo(`/pages/work/question/multipleChoices?id=`+ this.active.id)
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.container{
		background-color: #fff;
		height: 100vh;
		padding-top: 32rpx;
		.topTitle{
			padding-left: 40rpx;
			font-size: 14px;
			font-family: Roboto-Bold, Roboto;
			font-weight: bold;
			color: #000000;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.right{
				text{
					padding-right: 40rpx;
					color: #508CFF;
				}
			}
		}
		.reportView{
			width: calc(100% - 80rpx);
			margin: 30rpx 40rpx;
			padding-top: 10rpx;
			font-size: 14px;
			font-family: Inter-Regular, Inter;
			font-weight: 400;
			color: #5E5E5E;
			border-bottom: 1px solid #F5EFEF;
			.titleView{
				display: flex;
				align-items: flex-start;
				justify-content: flex-start;
				margin-bottom: 10px;
				text{
					display: block;
				}
				.blue{
					color:  #508CFF;
					font-size: 12px;
					width: 40px;
				}
			}
			.descView{
				font-size: 10px;
				font-family: Roboto-Regular, Roboto;
				font-weight: 400;
				color: #A3A3A3;
				display: flex;
				align-items: center;
				justify-content: space-between;
				line-height: 80rpx;
				.blue{
					color: #508CFF;
				}
				.rate{
					display: inline-block;
				}
				
			}
		}
		
		.addView{
			width: 600rpx;
			height: 480rpx;
			padding: 40rpx;
			border-radius: 20rpx;
			.topTitle{
				padding: 0;
			}
			.publicBtn{
				background: rgba(80, 140, 255, 1);
				color: #fff;
				width: 130rpx;
				display: block;
				margin-top: 30rpx;
				border-radius: 40rpx;
			}
		}
		.load-more{
			display: block;
			padding: 20px;
			margin: 0 auto;
			text-align: center;
		}
		.popup{
			height: 157px;
			background: #FFFFFF;
			text{
				line-height: 50px;
				display: block;
				text-align: center;
				font-family: Roboto-Regular, Roboto;
				font-weight: 400;
				color: #000000;
				font-size: 16px;
			}
			.cancel{
				color: #F26D6D;
			}
		}
	}
</style>